new Vue({
    el: "#main",
    data: {
        // 控制页面大小及其右上角用户名
        user: {
            userName: "user",
            role: "游客"
        },
        main_style: "height: 1000px; border: 1px solid rgb(17, 18, 21)",
        dataList: [], //当前页要展示的列表数据
        amount :"",
        allNum :"",
        pagination: { //分页相关模型数据
            currentPage: 1, //当前页码
            pageSize: 10, //每页显示的记录数
            pageSizes: [10, 20, 30, 40, 50],
            total: 0, //总记录数
            type: "",
            userName: "",
            newsName: "",
            description: ""
        }

    },
    methods: {
        autodivheight() {
            //获取浏览器窗口高度
            var winHeight = 0;
            if (window.innerHeight)
                winHeight = window.innerHeight;
            else if ((document.body) && (document.body.clientHeight))
                winHeight = document.body.clientHeight;
            //通过深入Document内部对body进行检测，获取浏览器窗口高度
            if (document.documentElement && document.documentElement.clientHeight)
                winHeight = document.documentElement.clientHeight;
            //DIV高度为浏览器窗口的高度
            console.log(winHeight)
            setTimeout(() => {
                this.main_style = "height:" + winHeight + "px;" + " border: 1px solid rgb(17, 18, 21)"
            }, 1000)


            // document.getElementByClassName("main_test").style.height = winHeight + "px";
            console.log()
            //DIV高度为浏览器窗口高度的一半
            //document.getElementById("test").style.height= winHeight/2 +"px";
        },
        getUserRole(){
            //获取用户权限角色
            axios.get("/user/get/now").then(
                res=>{
                    if(res.data.code==='200'){
                        this.user.userName = res.data.data.name
                        this.user.role = res.data.data.role
                        this.getAll()
                    }else{
                        this.$message.error("请登录....")
                        window.setTimeout(()=>{
                            window.location.href="/index.html"
                        },1000)
                    }

                }
            )
        },
        toApply(){
            this.total =  parseFloat(parseFloat(this.addForm.num)*parseFloat(this.addForm.price)).toFixed(2)
            // alert(this.total.valueOf())
            this.dialogIsAddVisible=true
            this.dialogAddVisible=false

        },
        toBilling(){

        },
        logout(){
            axios.post("/user/logout").then(
                res=>{
                    if(res.data.code==='200'){
                        this.$message.success("登出成功")
                        window.setTimeout(()=>{
                            window.location.href="/index.html"
                        },1000)
                    }else{
                        this.$message.error("登出失败....")
                    }
                }
            )
        },
        getAll() {
            console.log(this.pagination)
            axios.get("/order/get/page", {
                params: {
                    userName: this.pagination.userName,
                    newsName: this.pagination.newsName,
                    page: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize
                }
            }).then(
                res => {
                    // console.log(res.data)
                    this.dataList = res.data.data.dataList
                    this.amount = res.data.data.amount
                    this.allNum = res.data.data.allNum
                    this.pagination.total = res.data.data.total
                }
            )
        },
        handleSizeChange(val) {
            //console.log(`每页 ${val} 条`);
            this.pagination.pageSize = val;
            this.getAll();
        },
        handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
            this.pagination.currentPage = val;
            this.getAll();
        },
        handleDelete(row) {
            axios.delete("/order/delete/" + row.id).then(
                res => {
                    this.getAll()
                    if (res.data.code === '200') {
                        this.$message.success("删除成功")
                    } else {
                        this.$message.error("删除失败")
                    }
                }
            )
        },
    },
    created() {
        // window.alert("欢迎光临")
        this.getUserRole()
    },
    mounted() {
        this.autodivheight();
    }
})